<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0 auto;
            padding: 0;
            list-style: none;
        }
        .wrep{
            width: 700px;
            height: 400px;
            background: red;
            position: relative;
        }
        .imgbox{
            width: 700px;
            height: 400px;
            background-color: hotpink;
            overflow: hidden;
        }
        .imgbox  li{
            display: none;
        }
        .imgbox img{
            width: 700px;
            height: 400px;
            
        }
        .imgbox  li.active{
            display: block;
        }
        .lis {
            position: absolute;
            bottom: 0;
            left: 50px;
            width: 200px;
            height: 30px;
            background-color: rgba(0, 0, 0, 0.5);
        }
        .lis  li{
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: khaki;
            float: left;
            margin-left: 20px;
        }
        .left{
            width: 20px;
            height: 50px;
            background: #ccc;
            position: absolute;
            left: 0;
            top: 50%;
            color: white;
        }
        .right{
            width: 20px;
            height: 50px;
            background: #ccc;
            position: absolute;
            right: 0;
            top: 50%;
            color: white;
        }
        .lis .on{
            background-color: royalblue;
        }
    </style>
</head>
<body>
    <div class="wrep">
        <div class="imgbox">
            <ul>
                <!-- <li></li>
                <li></li>
                <li></li>
                <li></li> -->
            </ul>
        </div>
        <div class="lis">
           <ul>
               
           </ul>
        </div>
        <div class="left"><</div>
        <div class="right">></div>

    </div>
    <script>
        var arr=['./img/1.jpg','./img/2.jpg','./img/3.jpg','./img/4.jpg']
        function Big(obj){

            Object.assign(this,obj);

             
             this.init();
        }
        Big.prototype={
            constructor:Big,

            init:function(){
               this.index=0;
               this.t=null;
                this.Box();
                
                this.Js();
                this.Hua();
                this.Dj();
                
            },

            Box:function(){
              this.imgbox.innerHTML=this.arr.map((v,i)=>{
                  return `<li class="${this.index==i ? 'active' : ''}"><img src='${v}'></li>`
              }).join('')
              this.lis.innerHTML=arr.map((v,i)=>{
                  return `<li class="${this.index==i ? 'on' : ''}"></li>`
              }).join('')
            },
            Js:function(){
               this.t= setInterval(() => {
                    this.index++;
                    if(this.index>=this.arr.length){
                        this.index=0;
                    }
                    this.Box();
                }, 1000);
                
            },
            Hua:function(){
                this.wrep.addEventListener('mouseover',()=>{
                    clearInterval(this.t);
                })
                this.wrep.addEventListener('mouseout',()=>{
                    this.Js();
                })
            },
            Dj:function(){
                this.wrep.addEventListener('click',(e)=>{
                    var t=e.target;
                    if(t.nodeName=='LI'){
                        this.index=[...this.lis.children].indexOf(t);
                        this.Box();
                    }
                })
                   this.left.addEventListener('click',()=>{
                       this.index--;
                       console.log(this.index);
                       if(this.index<0){
                           this.index=this.arr.length-1;
                       }
                       this.Box();
                   })
                   this.right.addEventListener('click',()=>{
                      
                    this.index++;
                    console.log(this.index);

                    if(this.index>=this.arr.length){
                        this.index=0;
                    }
                       this.Box();
                   })
               
            }

        }
        new Big({
            wrep:document.querySelector('.wrep'),
            imgbox:document.querySelector('.imgbox'),
            lis:document.querySelector('.lis'),
            left:document.querySelector('.left'),
            right:document.querySelector('.right'),
            arr:arr
        });
    </script>
</body>
</html>